package com.carltechnology.mahjonggamecaculation.views.impl;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.LinearLayout;

import com.carltechnology.mahjonggamecaculation.R;
import com.carltechnology.mahjonggamecaculation.presenter.IMahjongGameInputPresenter;
import com.carltechnology.mahjonggamecaculation.presenter.impl.MahjongGameInputPresenter;
import com.carltechnology.mahjonggamecaculation.utils.views.TextEditView;
import com.carltechnology.mahjonggamecaculation.views.IMahjongGameInputView;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by WZTCM on 2016/6/29.
 */
public class MahjongGameInputActivity extends AppCompatActivity implements IMahjongGameInputView {
    public static final String EXTRA_DATA_NAME = "perunit";
    public enum MSG_TYPE {
        SUCCESS_INPUT("输入正确，完成插入"),
        PLAYER1_UNCORRECT("请正确输入玩家1的姓名"),
        PLAYER2_UNCORRECT("请正确输入玩家2的姓名"),
        PLAYER3_UNCORRECT("请正确输入玩家3的姓名"),
        PLAYER4_UNCORRECT("请正确输入玩家4的姓名"),
        PERUNIT_UNCORRECT("请正确输入此局单价"),
        CHINESE_ONLY("只能输入中文名"),
        PLAYERS_REPEAT("已存在此局");
        private String msg;

        MSG_TYPE(String msg) {
            this.msg = msg;
        }

        @Override
        public String toString() {
            return msg;
        }
    }

    private Handler handler = new Handler();
    private IMahjongGameInputPresenter presenter;
    @InjectView(R.id.mahjonggame_input_perunit)
    TextEditView perunitView;
    @InjectView(R.id.mahjonggame_input_player1)
    TextEditView player1View;
    @InjectView(R.id.mahjonggame_input_player2)
    TextEditView player2View;
    @InjectView(R.id.mahjonggame_input_player3)
    TextEditView player3View;
    @InjectView(R.id.mahjonggame_input_player4)
    TextEditView player4View;
    @InjectView(R.id.mahjonggame_input_container)
    LinearLayout container;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mahjonggame_input);
        ButterKnife.inject(this);
        presenter = MahjongGameInputPresenter.newInstance(this);
    }

    @Override
    public String getEditPlayer1() {
        return player1View.getEditTextContent();
    }

    @Override
    public String getEditPlayer2() {
        return player2View.getEditTextContent();
    }

    @Override
    public String getEditPlayer3() {
        return player3View.getEditTextContent();
    }

    @Override
    public String getEditPlayer4() {
        return player4View.getEditTextContent();
    }

    @Override
    public String[] getAllPlayerNames() {
        String[] names = new String[4];
        names[0] = player1View.getEditTextContent();
        names[1] = player2View.getEditTextContent();
        names[2] = player3View.getEditTextContent();
        names[3] = player4View.getEditTextContent();
        return names;
    }

    @Override
    public String getEditPerUnit() {
        return perunitView.getEditTextContent();
    }

    @Override
    public Handler getHandler() {
        return handler;
    }

    @Override
    public LinearLayout getContainer() {
        return container;
    }

    @Override
    public void toRunningActivity() {
        Intent intent = new Intent(this, MahjongRunningGameActivity.class);
        startActivity(intent);
        finish();
    }



    @OnClick(R.id.mahjonggame_input_button_cancel)
    public void onCancel(View view) {
        finish();

    }

    @OnClick(R.id.mahjonggame_input_button_yes)
    public void onYes(View view) {
        presenter.examineAndStoreMahjongGameInfo();
    }


}
